package com.gkey.base.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.gkey.base.cache.PathParameter;
import com.gkey.base.cache.UsualParameter;
import com.gkey.core.web.util.SessionUtil;
import com.gkey.sole.dict.bean.DPathParam;

@Controller
@RequestMapping(value = "/")
public class PortalController extends MultiActionController{
	
	private Logger log = Logger.getLogger(PortalController.class);
	
	@RequestMapping
    public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		try {
			DPathParam param = PathParameter.AcquirePathModel(request.getRequestURL()+"");
	    	request.getSession().setAttribute("params", param);
	    	Object o = SessionUtil.getSessionAttribute(request, UsualParameter.SESSION_USER);
	    	if(o!=null){
	    		return "redirect:/welcome";
	    	}
	    	return param.getWebprefixs() + "login";
		} catch (Exception e) {
			log.error("PortalController产生错误，请首先检查 数据库连接是否成功！", e);
		}
        return "cb_login";
    }    
}
